package com.example.mapper;

import com.example.dto.AdminOrderDetail;
import com.example.dto.AdminOrderDto;
import com.example.dto.ImportOrderDto;
import com.example.dto.SearchOrderDto;
import com.example.entity.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.SqlProvider;

import java.util.List;

/**
* @author circle48
* @description 针对表【order(订单)】的数据库操作Mapper
* @createDate 2024-06-03 22:44:33
* @Entity com.example.entity.Order
*/
@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Select("SELECT order_sn, user_name, pay_amount, status, payment_time, pay_type FROM `order`")
    List<AdminOrderDto> getOrderList();

    @Select({"<script>",
            "SELECT * FROM `order`",
            "<where>",
            "<if test='orderNo != null and orderNo.trim() != \"\"'>AND order_sn LIKE CONCAT('%', #{orderNo}, '%')</if>",
            "<if test='memberName != null and memberName.trim() != \"\"'>AND user_name LIKE CONCAT('%', #{memberName}, '%')</if>",
            "<if test='orderTime != null'>AND payment_time >= #{orderTime}</if>",
            "</where>",
            "</script>"})
    List<AdminOrderDto> searchOrderList(SearchOrderDto searchOrderDto);

    @Select("SELECT * FROM `order` WHERE order_sn = #{orderSn}")
    Order getOrderDetail(String orderSn);

    @Select("SELECT order_sn FROM `order` WHERE id = #{OrderId}")
    String getOrderSnById(Long OrderId);

    @Select("SELECT * FROM `order` WHERE id = #{OrderId}")
    Order selectByOrderId(Long OrderId);

    @Select("select * from `order` where store_id = #{storeId}")
    List<Order> getSellerOrderList(Long storeId);

    @Update("<script>"
            + "UPDATE `order` "
            + "SET status = 2, "
            + "delivery_sn = #{deliverySn}, "
            + "modify_time = NOW() "
            + "WHERE order_sn = #{orderSn} "
            + "AND status = 1"
            + "</script>")
    void updateOrder(ImportOrderDto testDto);

    @Select("select user_id from `order` where id=#{orderId}")
    Long getUserIdByOrderId(Long orderId);
}




